package com.yuntian.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import org.springframework.stereotype.Component;

import java.io.IOException;
/*@Component
@WebFilter(urlPatterns = "/*")*/
public class DemoFilter implements Filter {
    @Override//初始化方法，只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override//拦截到请求调用，调用多次
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("拦截到请求");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override//销毁方法，调用一次
    public void destroy() {
        Filter.super.destroy();
    }
}
